﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Player : MonoBehaviour
{
    public float MoveSpeed = 20.0f;
    float x = 0;
    float y = 0;
    float xSpeed = 0;
    float ySpeed = 0;
    public GameObject maincanmerarotation;

    enum RotationAxes { MouseXAndY, MouseX, MouseY }
    RotationAxes axes = RotationAxes.MouseXAndY;
    //@HideInInspector
    float sensitivityX = 15;
    //@HideInInspector
    float sensitivityY = 15;
    //private float minimumX = -360; 原文有此行但并未使用此变量
    //private float maximumX = 360; 同上
    float minimumY = -80;
    float maximumY = 80;
    private float rotationY = 0;

    Animator anim;


    public bool sunceopen=true;
    public Text moneytext;
    public int money = 0;
    // Start is called before the first frame update
    void Start()
    {
        anim = transform.GetComponent<Animator>();
    }
    void BioodOperation()
    {

    }
    // Update is called once per frame
    void Update()
    {
        //移动
        Move();
        //角度
        RotationPlayer();
    }
    void Move()
    {
        //向前移动
        if (Input.GetKey(KeyCode.W ))
        {
            anim.SetBool("Run", true);
            transform.Translate(Vector3.forward * Time.deltaTime * MoveSpeed);
        }
        //向后移动
        if (Input.GetKey(KeyCode.S ))
        {
            anim.SetBool("Run", true);
            transform.Translate(Vector3.back * Time.deltaTime * MoveSpeed);
        }
        //向右移动
        if (Input.GetKey(KeyCode.A ))
        {
            anim.SetBool("Run", true);
            transform.Translate(Vector3.left * Time.deltaTime * MoveSpeed);
        }
        //向左移动
        if (Input.GetKey(KeyCode.D ))
        {
            anim.SetBool("Run", true);
            transform.Translate(Vector3.right * Time.deltaTime * MoveSpeed);
        }
        if (!Input.GetKey(KeyCode.D) && !Input.GetKey(KeyCode.W) && !Input.GetKey(KeyCode.S) && !Input.GetKey(KeyCode.A))
        {
            anim.SetBool("Run", false);
        }
    }
    void RotationPlayer()
    {
        if (Input.GetMouseButton(1))
        {
            if (axes == RotationAxes.MouseXAndY)
            {
                float rotationX = transform.localEulerAngles.y + Input.GetAxis("Mouse X") * sensitivityX;
                rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
                rotationY = Mathf.Clamp(rotationY, minimumY, maximumY);
                transform.localEulerAngles = new Vector3(0, rotationX, 0);
            }
            else if (axes == RotationAxes.MouseX)
            {
                transform.Rotate(0, Input.GetAxis("Mouse X") * sensitivityX, 0);
            }
            else
            {
                rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
                rotationY = Mathf.Clamp(rotationY, minimumY, maximumY);
                transform.localEulerAngles = new Vector3(-rotationY, transform.localEulerAngles.y, 0);
            }
        }
    }
}
